import type { UserItem } from '@/types/userType'
import { create } from 'zustand'

interface Store {
  token: string
  collapsed: boolean
  user: UserItem
  updateUser: (user: UserItem) => void
  updateToken: (token: string) => void
  updateCollapsed: () => void
}
const useStore = create<Store>(set => ({
  token: '',
  collapsed: false,
  user: {
    createId: 0,
    deptId: '',
    deptName: '',
    job: '',
    mobile: '',
    role: 0,
    state: 0,
    userEmail: '',
    userId: 0,
    userImg: '',
    userName: '',
    _id: ''
  },
  updateUser: (user: UserItem) => set(() => ({ user })),
  updateToken: (token: string) => set({ token }),
  updateCollapsed: () => set(state => ({ collapsed: !state.collapsed }))
}))

export default useStore
